<div class="span3" id="backupschedule-add-block">
	<h4 class="title"><?php echo t('page', 'Add Scheduled Backup'); ?></h4>
	<div class="squiggly-border"></div>
	<div class="row-fluid">
		<div class="span12 add_backupschedule_form_info hide" id="add_backupschedule_error_info">
			<div class="alert alter-block alert-error">
	<!--			<button type="button" class="close" data-dismiss="alert">&times;</button>-->
				<h4>Error</h4>
				<div class="content"></div>
			</div>
		</div>
	</div>
	<div class="row-fluid">
		<div class="span12 hide" id="add_backupschedule_success_info">
			<div class="alert alter-block alert-success">
	<!--			<button type="button" class="close" data-dismiss="alert">&times;</button>-->
				<h4>Success</h4>
				<div class="content">New backupschedule has been added!</div>
			</div>
		</div>
	</div>
	
	<?php $form = $this->beginWidget('CActiveForm', array(
		'id' => 'backupschedule-add-form',
		'enableClientValidation' => true,
		'clientOptions' => array(
			'validateOnSubmit' => true,
		),
	));$form= new CActiveForm(); ?>
		<div class="row-fluid">
			<?php echo $form->textField($backupScheduleAddForm, 'name', array('placeholder' => $backupScheduleAddForm->getFieldLabel('name'), 'class' => 'fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->dropDownList($backupScheduleAddForm, 'group_account_host', $backupScheduleAddForm->listGetBy(), array('class' => 'fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo CHtml::dropDownList('id_group', '', $backupScheduleAddForm->listGroups(), array('class' => 'group_account_host_value hide')); ?>
			<?php echo CHtml::dropDownList('id_host', '', $backupScheduleAddForm->listHosts(), array('class' => 'group_account_host_value hide')); ?>
			<?php echo CHtml::dropDownList('id_account', '', $backupScheduleAddForm->listAccounts(), array('class' => 'group_account_host_value hide')); ?>
		</div>
		<label class="checkbox">
			<?php echo t('page', 'Select All cPanel Accounts'); ?>
			<?php echo CHtml::checkBox('checkall_cpanelaccounts', false, array('class' => 'checkallbox', 'data-checkall-select' => 'cpanel_accounts')); ?>
		</label>
		<?php echo $form->dropDownList($backupScheduleAddForm, 'cpanel_accounts', array(), array('class' => 'chzn-select checkallselect', 'data-checkall-box' => 'checkall_cpanelaccounts', 'data-placeholder' => t('info', 'Select cPanel Accounts To Backup...'), 'multiple' => true, 'style' => 'tabindex=4')); ?><br />
		<div class="row-fluid">
			<?php echo $form->dropDownList($backupScheduleAddForm, 'id_backup_locations', $backupScheduleAddForm->listBackupLocation(), array('class' => 'fields', 'placeholder' => $backupScheduleAddForm->getFieldLabel('id_backup_schedules'))); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->textField($backupScheduleAddForm, 'email', array('placeholder' => $backupScheduleAddForm->getFieldLabel('email'), 'class' => 'fields')); ?>
		</div>
		<div class="row-fluid">
			<div class="input-append">
				<?php echo $form->textField($backupScheduleAddForm, 'delay', array('placeholder' => $backupScheduleAddForm->getFieldLabel('delay'), 'class' => 'fields')); ?>
				<span class="add-on">sec</span>
			</div>
		</div>
		<div class="row-fluid">
			<?php echo $form->dropDownList($backupScheduleAddForm, 'status', $backupScheduleAddForm->listStatus(), array('class' => 'fields')); ?>
		</div>
		<h5>Backup Time</h5>
		<strong>Current Server Date &amp; Time:</strong><br>
		<?php echo date('D, M d, Y H:m'); ?>
		<?php echo $form->dropDownList($backupScheduleAddForm, 'days', $backupScheduleAddForm->listDays(), array('class' => 'chzn-select', 'options'=>array(BackupSchedule::Sun => array('selected' => 'selected')), 'data-placeholder' => t('info', $backupScheduleAddForm->getFieldLabel('days')), 'multiple' => true, 'style' => 'tabindex=4')); ?><br />
		<?php echo $form->dropDownList($backupScheduleAddForm, 'hour', $backupScheduleAddForm->listHours()); ?>
		
		<div class="row-fluid rows">
			<?php echo CHtml::ajaxSubmitButton(
				t('buttons', 'Add Scheduled Backup'), 
				app()->createUrl('backup/schedule/index'),
				array(
					'type' => 'post',
					'beforeSend' => 'function(){
						//$("#add_backupschedule_submit").button("loading");
					}',
					'success' => 'function(ret){
						$("#add_backupschedule_submit").button("reset");
						if(ret["result"]){
							$("#add_backupschedule_success_info").blink({
								"beforeCall": function(){
									var tr = $("<tr class=\"new-line\" />");
									tr.append( $("<td class=\"hide id_backup_schedule\" />").html(ret["detail"]["id_backup_schedule"]) );
									tr.append( $("<td class=\"name\" />").html(ret["detail"]["name"]) );
									tr.append( $("<td class=\"id_backup_locations\" />").html(ret["detail"]["locationName"]) );
									tr.append( $("<td class=\"status\" />").html(ret["detail"]["statusTxt"]) );
									tr.append( $("<td class=\"days\" />").html(ret["detail"]["daysTxt"]) );
									tr.append( $("<td class=\"hour\" />").html(ret["detail"]["hour"]) );
									tr.append( $("<td />").html('.json_encode(BackupSchedule::model()->renderListActionButtons()).') );
									
									$("#backupschedule_grid table").prepend(tr);
									
									$(".new-line").removeClass("new-line");
									$("form#backupschedule-add-form .fields").val("");
								}
							});
						}else{
							$("#add_backupschedule_error_info").blink({
								"beforeCall": function(){
									$("#add_backupschedule_error_info .content").html("");
									$.each(ret["errors"], function(attrName, error){
										$(error).each(function(k, e){
											var p = $("<p />").addClass("text-error").append(attrName+": "+e);
											$("#add_backupschedule_error_info .content").append(p);
										});
									});
								}
							});
						}
					}',
					'dataType' => 'json'
				),
				array(
					'id' => 'add_backupschedule_submit',
					'type' => 'button', 
					'class' => 'btn btn-primary',
					'data-loading-text' => t('buttons', 'Saving...')
				)
			); ?>
		</div>
	<?php $this->endWidget(); ?>
	
	<script>
		$(document).ready(function(){
			$(".chzn-select").chosen(); 

			$('.checkallbox').click(function(){
				if($(this).is(':checked')){
					$('#'+$(this).attr('data-checkall-select')+' option').attr('selected', true);
				}else{
					$('#'+$(this).attr('data-checkall-select')+' option').removeAttr('selected');
				}
				$('#'+$(this).attr('data-checkall-select')).change().trigger('liszt:updated');
			});
			
			$('.checkallselect').change(function(){
				var checkallbox = $('#'+$(this).attr('data-checkall-box'));
				checkallbox.attr('checked', true);
				$.each($(this).children('option'), function(k, v){
					if(!$(v).is(':selected')){
						checkallbox.removeAttr('checked');
						return true;
					}
				});
			});

			$('#BackupScheduleAddForm_group_account_host').change(function(){
				$('.group_account_host_value').hide();
				$('.group_account_host_value#'+$(this).val()).show().change();
			}).change();

			$('.group_account_host_value').change(function(){
				var obj = $(this);
				var type = $(this).attr('id');
				var CpanelAccountsSearchForm = {};
				CpanelAccountsSearchForm[type] = $(this).val();
				$.ajax({
					url: <?php echo json_encode(url('whm/cpanelaccount/searchresult')); ?>,
					type: 'post',
					data: {
						'CpanelAccountsSearchForm': CpanelAccountsSearchForm
					},
					success: function(cpanelAccounts){
						$('#BackupScheduleAddForm_cpanel_accounts').html('');
						$.each(cpanelAccounts, function(id_cpanel_accounts, domain){
							$('#BackupScheduleAddForm_cpanel_accounts').append(
								$('<option />').attr('value', id_cpanel_accounts).text(domain)
							);
						});
						$('#BackupScheduleAddForm_cpanel_accounts').change().trigger('liszt:updated');
					},
					dataType: 'json'
				});
			});
		});
	</script>
</div>